package de.tg.handball.xml;

import java.util.Date;

import de.tg.handball.util.Util;

public class RSSItem implements Comparable<RSSItem>{
	private String _title = null;
	private String _description = null;
	private String _link = null;
	private String _category = null;
	private Date _pubdate = null;

	RSSItem() {
	}

	public void setTitle(String title) {
		if (_title == null)
			_title = title;
		else
			_title += title;
		_title = _title.trim();
	}

	public void setDescription(String description) {
		if (_description == null)
			_description = description;
		else
			_description += description;
		_description = _description.trim();
	}

	public void setLink(String link) {
		if (_link == null)
			_link = link;
		else
			_link += link;
	}

	public void setCategory(String category) {
		_category = category;
	}

	public void setPubDate(String pubdate) {
		_pubdate = Util.parseRSSDate(pubdate);
	}

	public String getTitle() {
		return _title;
	}

	public String getDescription() {
		return _description;
	}

	public String getLink() {
		return _link;
	}

	public String getCategory() {
		return _category;
	}

	public Date getPubDate() {
		return _pubdate;
	}

	@Override
	public String toString() {
		return "RSSItem [_title=" + _title + ", _description=" + _description
				+ ", _link=" + _link + ", _category=" + _category
				+ ", _pubdate=" + _pubdate + "]";
	}

	public int compareTo(RSSItem another) {
		if(_pubdate == null)
			return 1;
		if(another._pubdate == null)
			return -1;
		int i = _pubdate.compareTo(another._pubdate);
		if(i == 0)
			i= _title.compareTo(another._title);
		
		return -i;
	}

}
